package com.sanqing.model;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;

import com.sanqing.dao.Dao;

public class common {
    public static  String UserName;
    public static void check()
    {
    	DateTimeFormatter dateTimeFormatter1=DateTimeFormatter.ofPattern("yyyy-MM-dd");
    	String borrowDate1=dateTimeFormatter1.format(LocalDate.now());
    	String borrowDate=dateTimeFormatter1.format(LocalDate.now().minusDays(7));
    	ArrayList list=(ArrayList) Dao.selectReserve("select * from tb_reserve where reserveDate IS NOT NULL and reserveDate<'"+borrowDate+"'");
    	for(int i=0;i<list.size();i++)
    	{
    		Reserve reserve=(Reserve)list.get(i);
    		//System.out.println(reserve.getreaderISBN());
    		Dao.InsertBorrow("delete from tb_reserve where readerISBN='"+reserve.getreaderISBN()+"' and bookISBN='"+reserve.getbookISBN()+"'");
    		String se=Dao.selectReserveReaderISBN("select * from tb_reserve where bookISBN='"+reserve.getbookISBN()+"' and reserveDate IS NULL LIMIT 1");
    		//System.out.println(se);
    		Dao.InsertBorrow("update tb_reserve set reserveDate = '"+borrowDate1+"' where readerISBN = '"+se+"'and bookISBN='"+reserve.getbookISBN()+"'");
    	}
    }
}
